var Resp = {
    sysConnected: function(data) {
        this.log('server connected')
        this.log(data)
    },
    sysHeart: function(data) {
        this.log('heart received')
        this.log(data);
    },
    sysLogin: function(data) {
        this.log('user login ok')
        this.log(data)
        User.setUser(data.user);
        this.changeStatus('start');
    },
    sysReconnected: function(data) {
        this.log('user reconnected');
        this.log(data);
        //User.setUser(data.user);
    },
    sysLogout: function(data) {
        this.log('user logout')
        this.log(data)
    },
    gameStart: function(data) {
        this.log('game start')
        this.log(data)
        this.changeStatus('playing');
    },
    gameUserJoin: function(data) {
        this.log('user join')
        this.log(data)
        this.changeStatus('wait');
        /*if (data.user.id == User.getUser().id) {
            $('#chat-message-panel').append('<div>等待其它玩家</div>')
        } else {
            $('#chat-message-panel').append('<div>'+ data.user.nickname +'进入房间</div>')
        }*/
        this.setTitle('等待开始')
        this.render(data);
    },
    gameUserLeave: function(data) {
        this.log('user leave')
        this.log(data)
        this.changeStatus('wait');
        $('#chat-message-panel').append('<div>'+ data.user.nickname +'离开房间</div>')
        this.setTitle('等待玩家进入');
    },
    gameReady: function(data) {
        this.log('user ready')
        this.log(data)
        if (data.user.status == 2) {
            this.changeStatus('playing');
            this.setTitle('准备就绪,等待其它玩家开始');
            data.room.holes = [];
            data.room.outs = [];
            data.hands = [];
        }
        this.render(data);
    },
    gameSendCard: function(data) {
        this.log('game send card')
        this.log(data)
        this.setTitle('正在发牌')
        this.render(data);
    },
    gameUserCall: function(data) {
        this.log('user call')
        this.log(data)
        this.setTitle('等待叫地主');
        this.changeStatus('playing');
        if (data.user.position == data.room.current) {
            this.changeStatus('playing call');
            this.setTitle('请叫地主');
        }
        this.render(data);
    },
    gameBasecard: function(data) {
        this.log('base card')
        this.log(data)
        this.changeStatus('playing');
        this.setTitle('拿底牌');
        if (data.user.position == data.room.current) {
            this.changeStatus('playing out');
        }
        //$('#chat-message-panel').append('<div>'+ data.user.nickname +'拿底牌</div>')
        this.render(data);
    },
    gameOutCard: function(data) {
        this.log('out card')
        this.log(data)
        this.changeStatus('playing');
        this.setTitle('等待出牌');
        if (data.user.position == data.room.current) {
            this.changeStatus('playing out');
            this.setTitle('请出牌');
        }
        this.render(data);
    },
    gameOver: function(data) {
        this.log('game over')
        this.log(data)
        this.changeStatus('gameover');
        
        var container = $('#gameover-panel .userlist').empty();
        if (data.wintype == 1) {
            container.append('<div>地主胜</div>');
            this.setTitle('地主获胜');
        } else {
            container.append('<div>长工胜</div>');
            this.setTitle('长工获胜');
        }
        $.each(data.users, function(idx, user){
            var item = $('<div>'+ user.nickname + (user.master ? '(地主)' : '') +'</div>');
            container.append(item);
        })
    },
    gameInfo: function(data) {
        this.log('game info')
        this.log(data)
    },
    chatMsg: function(data) {
        this.log('chat msg')
        this.log(data)
        $('#chat-message-panel').append('<div>'+ data.user.nickname +':'+ data.content +'</div>')
    },
    render: function(data) {
        if (data.users) {
            data.game.renderUsers(data);
        }
        if (data.room.holes) {   //底牌
            data.game.renderHoles(data.room.holes);
        }
        if (data.hands) {   //我的手牌
            data.game.renderHands(data.hands);
        }
        if (data.room.outs) {    //上家出牌
            data.game.renderOuts(data.room.outs);
        }
    },
    changeStatus(cls) {
        $('#board').removeClass($('#board').attr('class')).addClass(cls);
    },
    setTitle(title) {
        $('#table-status').text(title);
    },
    log: function(data) {
        console.log(data)
    },
    showTips: function(tips) {
        console.log(tips);
    }
}